
export default class MathHelper  {

    private static vector:cc.Vec2 = cc.v2(0,0);
    static getRadian(node1:cc.Node,node2:cc.Node ): number{
        return this.getRadianByXY(node1.x,node1.y,node2.x,node2.y);
    }    

    static getAngle(node1:cc.Node,node2:cc.Node){
        return this.getRadian(node1,node2) * Math.PI;
    }
    static getAngleByRadian(radian:number){
        return radian * 57.3
    }

    static getRadianByXY(x1:number,y1:number,x2:number,y2:number ){
        let disx = Math.abs(x2- x1);
        let disy = Math.abs(y2- y1);
        // let disx = targetPos.x - selfPos.x  ;
        // let disy = targetPos.y  - selfPos.y  ;
        let dis = Math.sqrt(disx*disx + disy * disy)
        let radian:number = Math.asin(disx / dis) 
        // cc.log(' disx ',disx,' disy ',disy,' dis ',dis)
        return radian;
    }

    static getAngleByXY(x1:number,y1:number,x2:number,y2:number ){
        return this.getRadianByXY(x1,y1,x2,y2) * Math.PI;
    }

    static getDir(node1:cc.Node,node2:cc.Node):cc.Vec2{
        return this.getDirByXY(node1.x,node1.y,node2.x,node2.y);
    }

    static getDirByXY(x1:number,y1:number,x2:number,y2:number ):cc.Vec2{
        let x = 0;
        if(x2 > x1){
            x = 1;
        }else if(x2 < x1){
            x = -1;
        }
        let y = 0;
        if(y2 > y1){
            y = 1;
        }else if(y2 < y1){
            y = -1;
        }
        this.vector.x = x;
        this.vector.y = y;
        return this.vector;
    }
}
